<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Repositories\GameServer\OrderRepository;

class OrderController extends Controller
{
    protected $Order;

    public function __construct(OrderRepository $order)
    {
        $this->middleware('admin.auth');
        $this->Order = $order;
    }

    public function index(Request $request)
    {
        $date = $request->date;
        $status = $request->status;

        $where = [];

        if (!empty($date)) {
            $time = explode('~', $date);
            $where[] = ['created_at', '>=', $time[0]];
            $where[] = ['created_at', '<=', $time[1]];
        }

        if ($status !== null && $status !== 'all') {
            $where[] = ['status', $status];
        }

        $orders = $this->Order->getOrders($where);

        return view('admin.orders.index', compact('orders','date','status'));
    }
}
